package com.station.client.proxies;

import com.google.gwt.user.client.ui.Label;
import com.station.client.Listener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Jimmy87 on 26.12.13.
 */
public class PCashOffice extends PPlaceableEntity {

    final public double A92_PRICE = 27.0;
    final public double A95_PRICE = 30.0;
    final public double DIESEL_PRICE = 23.0;

    private double cash;
    private double maxCashAllowed;
    private transient List<Listener> listeners;

    {
        listeners = new ArrayList<Listener>();
        cash = 0;
        maxCashAllowed = 10000.0;
    }

    public PCashOffice(PCoordinates coordinates) {
        this.pCoordinates = coordinates;
    }

    public PCashOffice() {
    }

    public double getCash() {
        return cash;
    }

    public double increaseCash(double value, String fuelType) {
        double price = 0;
        if (fuelType.equals("A92"))
            price = value * A92_PRICE;
        if (fuelType.equals("A95"))
            price = value * A95_PRICE;
        if (fuelType.equals("DIESEL"))
            price = value * DIESEL_PRICE;
        cash += price;
        if (cash >= maxCashAllowed)
            notifyListeners();
        return price;
    }

    public double getMaxCashAllowed() {
        return maxCashAllowed;
    }

    public void setMaxCashAllowed(double maxCashAllowed) {
        this.maxCashAllowed = maxCashAllowed;
    }

    public void addListener(Listener listener) {
        listeners.add(listener);
    }

    public void notifyListeners() {
        for(Listener l : listeners)
            l.fireIncasatorEvent();
    }

    public double incasatorEvent() {
        double temp = cash;
        cash = 0;
        return temp;
    }

    public boolean isEmpty() {
        return 0.7 * maxCashAllowed >= cash;
    }

    public PCoordinates getNearCoordinates() {
        return new PCoordinates(pCoordinates.x + 1,pCoordinates.y);
    }
}
